from django.db import models

# Create your models here.
# models.py
from django.db import models


class Sku(models.Model):  # 商品链接表
    url = models.URLField(unique=True)  # 商品链接
    title = models.CharField(max_length=128, blank=True)  # 商品标题
    shop_name = models.CharField(max_length=128, blank=True)  # 店铺名称
    created_at = models.DateTimeField(auto_now_add=True)  # 创建时间
    last_crawled_at = models.DateTimeField(null=True, blank=True)  # 最后抓取时间


class PriceLog(models.Model):  # 商品具体信息表
    sku = models.ForeignKey(Sku, on_delete=models.CASCADE, related_name='logs')  # 关联商品id
    price = models.DecimalField(max_digits=10, decimal_places=2)  # 商品价格
    comment_number = models.CharField(max_length=50, blank=True, null=True)  # 商品评价数
    applause_rate = models.CharField(max_length=50, blank=True)  # 商品好评率
    title = models.TextField(blank=True)  # 商品标题
    sales = models.CharField(max_length=50, blank=True)
    store_rating = models.CharField(max_length=50, blank=True)  # 商店评分
    crawled_at = models.DateTimeField(auto_now_add=True)  # 抓取时间

    class Meta:
        ordering = ['-crawled_at']


class QueryLog(models.Model):  # 查询记录表
    sku = models.ForeignKey(Sku, on_delete=models.CASCADE)  # 关联商品id
    queried_at = models.DateTimeField(auto_now_add=True)  # 用户最新查询时间

    class Meta:
        ordering = ['-queried_at']
